/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
package com.eelpo.cmmp.uac.pages.home;

import com.eelpo.cmmp.core.wicket.behavior.JavascriptEventConfirmation;
import com.eelpo.cmmp.core.wicket.page.basic.DeniedPage;
import com.eelpo.cmmp.uac.session.UACSession;
import com.eelpo.common.util.DateFormatUtils;

import org.apache.wicket.Session;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.StatelessLink;

/**
 * <pre>
 * Top内容框架
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public class TopFrame extends DeniedPage {

	public TopFrame() {

		// 注销按钮
		renderLogout();

		// 登录用户名
		renderLoginUser();

		// 登录时间
		renderLoginTime();

		// 设置为无状态页面
		setStatelessHint(true);
	}

	public void renderLoginUser() {
		add(new Label("loginUser", UACSession.get().getUser().getName()));
	}

	public void renderLoginTime() {
		add(new Label("loginTime", DateFormatUtils.formatDateTime(UACSession.get().getUser().getLoginTime())));
	}

	/***
	 * 注销
	 * 
	 * @return
	 */
	private void renderLogout() {
		add(new StatelessLink("lnkLogout") {

			private static final long serialVersionUID = 4991630650192075372L;

			@Override
			public void onClick() {
				Session sessioin = Session.get();
				if (!sessioin.isSessionInvalidated()) {
					Session.get().invalidateNow();

					getRequestCycle().setRedirect(true);
					getRequestCycle().setResponsePage(Login.class);
				}
			}
		}.add(new JavascriptEventConfirmation("您确定要退出吗?")));
	}

}
